/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package folders2;


import javax.swing.JFileChooser;
import java.io.*;
import javax.swing.filechooser.FileSystemView;
/**
 *
 * @author Administrator
 */
public class RootFolders2 implements RootFolders2Interface
{
    private ProjectFile root;       //place where all users folders are placed on it
    private ProjectFile temp;       //place where all sent messages are placed on it
    /**
     * Constructor to initialize new root folders in the begining of releasing server to use
     */
    public RootFolders2()
    {
        root = new ProjectFile("root folder"); //make reference to root folder
        temp = new ProjectFile("temp folder"); //make reference to temp folder
    }
    /**
     * This method is used to get reference to root folder
     * which contains all users folders
     * @return reference to root folder
     */
    public ProjectFile getRoot()
    {
        return root;
    }
    /**
     * This method is used to set reference of root folders(i don't need to use it)
     * @param root new reference to root folder
     */
    public void setRoot(ProjectFile root)
    {
        this.root = root;
    }
    /**
     * This method is used to get reference to temp folder
     * which contains all sent messages
     * @return reference to temp folder
     */
    public ProjectFile getTemp()
    {
        return temp;
    }
    /**
     * This method is used to set new reference of temp folders(i don't need to use it)
     * @param temp new reference of temp folders
     */
    public void setTemp(ProjectFile temp)
    {
        this.temp = temp;
    }

    /**
    * I don't use it (excess code)
    * Create folder for new account in mail server in root folder
    * @param UserId represents folder name
    * @return reference of the folder created
    */
    public ProjectFile createAccountFolder(String UserId)
    {
        ProjectFile user = new ProjectFile(root.getMyFile(), UserId);
        user.getMyFile().mkdir();
        return user;        // return reference of the created folder
    }
    /**
     * I don't use it (excess code)
     * Create folder for new message in temp folder
     * @param message new message name
     * @return refernce to this message
     */
    public ProjectFile createTempFolder(String message)
    {
        ProjectFile m = new ProjectFile(temp.getMyFile(), message);
        m.getMyFile().mkdir();
        return m;
    }
    /**
     * (Excess code)
     * Use to delete folder in root or temp folder
     * @param dir   reference to that folder
     * @param key determinethe place of this folder
     * @return
     */
    /*public void deleteFolder(File dir, int key)
    {
    switch(key)
    {
    case 0:     //folder is in root folder
    {
    ProjectFile f = root.search(dir);
    f.deleteFile();
    }
    case 1:        //folder in temp folder
    {
    ProjectFile f = temp.search(dir);
    f.deleteFile();
    }
    }
    }*/
    /**
     * This method is used to create root foders
     */
    public void createRootFolders()
    {
            root.getMyFile().mkdir();
            temp.getMyFile().mkdir();
    }
    
}
